package com.kadron.session;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import com.kadron.common.KIDGenerator;
import com.kadron.common.KUtil;

public class Basket implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3243282634324553652L;
	
	private String uuid;
	private String comment;

	private Set<BasketItem> items = new LinkedHashSet<BasketItem>();
	
	public Basket() {
		super();
		this.uuid = KIDGenerator.createKID();
	}
	
	public String getUuid() {
		if (KUtil.isEmpty(uuid)) {
			this.uuid = KIDGenerator.createKID();
		}
		return uuid;
	}
	
	public void reset() {
		items.clear();
		comment = "";
	}
	
	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
	
	public List<BasketItem> getItemList() {
		return new LinkedList<BasketItem>(items);
	}
	
	public Set<BasketItem> getItems() {
		return items;
	}

	public void setItems(Set<BasketItem> items) {
		this.items = items;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Basket other = (Basket) obj;
		if (uuid == null) {
			if (other.uuid != null)
				return false;
		} else if (!uuid.equals(other.uuid))
			return false;
		return true;
	}

}
